package com.atguigu.encryptdecrypt;

import com.sun.org.apache.xml.internal.security.utils.Base64;

import java.security.*;

public class RSAdemo {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        //加密算法
        String algorithm  = "RSA";
        //创建密钥对生成器对象
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm);
        //生成密钥对
        KeyPair keyPair = keyPairGenerator.generateKeyPair();
        //生成私钥
        PrivateKey privateKey = keyPair.getPrivate();
        //生成公钥
        PublicKey publicKey = keyPair.getPublic();
        //获取私钥字节数组
        byte[] privateKeyEncoded = privateKey.getEncoded();
        //获取公钥字节数组
        byte[] publicKeyEncoded = publicKey.getEncoded();
        System.out.println("privateKeyEncoded = " + Base64.encode(privateKeyEncoded));
        System.out.println("publicKeyEncoded = " + Base64.encode(publicKeyEncoded));
        System.out.println("测试git提交");
        
    }


}
